package com.zf.proxy.cglib.subclass;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;

/**
 * cglib使用子类代理
 *
 * @author Zhou Feng
 */
public class TestCGSubMain {
    public static void main(String[] args) {
        // 设置这个变量后，Cglib会把Cglib动态代理生成的类写入到“指定的目录/全类名目录”，不设置则不写入
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, System.getProperty("user.dir") + "\\cglib");

        Enhancer enhancer = new Enhancer();
        //设置被代理的类
        enhancer.setSuperclass(CgSubA.class);
        //设置被代理的类的回调
        enhancer.setCallback(new CgSubAInterceptor());
        //生成代理对象
        CgSubA cgSubA = (CgSubA) enhancer.create();
        System.out.println(cgSubA.hello("hi"));

    }
}
